package com.javaeedev.lightweight.mvc.sample;

import javax.servlet.ServletContext;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.name.Names;
import com.javaeedev.lightweight.mvc.Action;
import com.javaeedev.lightweight.mvc.ExceptionResolver;
import com.javaeedev.lightweight.mvc.ServletContextAware;
import com.javaeedev.lightweight.mvc.ViewResolver;
import com.javaeedev.lightweight.mvc.sample.web.ExceptionHandler;
import com.javaeedev.lightweight.mvc.sample.web.RegisterAction;
import com.javaeedev.lightweight.mvc.sample.web.SignonAction;
import com.javaeedev.lightweight.mvc.sample.web.SignoutAction;
import com.javaeedev.lightweight.mvc.sample.web.StartAction;
import com.javaeedev.lightweight.mvc.sample.web.TestArrayAction;
import com.javaeedev.lightweight.mvc.sample.web.TransactionInterceptor;
import com.javaeedev.lightweight.mvc.view.VelocityViewResolver;

public class SampleModule implements Module, ServletContextAware {

    protected ServletContext context;

    public void setServletContext(ServletContext context) {
        this.context = context;
    }

    @SuppressWarnings("unchecked")
    public void configure(Binder binder) {
        // bind facade:
        binder.bind(Facade.class).to(FacadeImpl.class).asEagerSingleton();

        // bind interceptors:
        binder.bind(TransactionInterceptor.class).asEagerSingleton();

        // bind ViewResolver:
        binder.bindConstant().annotatedWith(Names.named("VelocityProperties")).to("/WEB-INF/velocity.properties");
        binder.bind(ViewResolver.class).to(VelocityViewResolver.class).asEagerSingleton();

        // bind ExceptionResolver:
        binder.bind(ExceptionResolver.class).to(ExceptionHandler.class).asEagerSingleton();

        // bind actions:
        binder.bind(Action.class).annotatedWith(Names.named("/start.do")).to(StartAction.class);
        binder.bind(Action.class).annotatedWith(Names.named("/register.do")).to(RegisterAction.class);
        binder.bind(Action.class).annotatedWith(Names.named("/signon.do")).to(SignonAction.class);
        binder.bind(Action.class).annotatedWith(Names.named("/signout.do")).to(SignoutAction.class);
        binder.bind(Action.class).annotatedWith(Names.named("/array.do")).to(TestArrayAction.class);
    }

}
